/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @param {number} val
 * @return {ListNode}
 */
var removeElements = function(head, val) {
    let headnode = new ListNode(0);
    headnode.next = head;
    let res = headnode;
    while (true) {
        if (res.next == null) { break; }
        if (res.next.val == val) {
            res.next = res.next.next;
        } else {
            res = res.next;
        }
    }
    return headnode.next;
};